<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Trie: iterators.cpp</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Trie
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">iterators.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>This example shows how to use iterator</p>
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * Copyright (c) 2012, Ranjith TV</span>
<span class="comment"> * All rights reserved.</span>
<span class="comment"> *</span>
<span class="comment"> * Licensed under the BSD 3-Clause (&quot;BSD New&quot; or &quot;BSD Simplified&quot;) license.</span>
<span class="comment"> * You may obtain a copy of the License at</span>
<span class="comment"> *</span>
<span class="comment"> * http://www.opensource.org/licenses/BSD-3-Clause</span>
<span class="comment"> *</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &lt;trie.h&gt;</span>
<span class="preprocessor">#include &lt;string&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;vector&gt;</span>

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> ** argv)
{

    <a name="_a0"></a><a class="code" href="classrtv_1_1_trie.html" title="Trie main class.">rtv::Trie&lt;char, std::string&gt;</a> dictionary(<span class="charliteral">&#39;\0&#39;</span>);

    dictionary.<a name="a1"></a><a class="code" href="classrtv_1_1_trie.html#aa9e051ae8d75ad29548412074d33e07a">insert</a>(<span class="stringliteral">&quot;karma$&quot;</span>, <span class="stringliteral">&quot;Destiny or fate, following as effect from cause&quot;</span>);

    rtv::Trie&lt;char, std::string&gt;::Iterator iter = dictionary.<a name="a2"></a><a class="code" href="classrtv_1_1_trie.html#ae72e5f97be19cbb9fe5da0c7f37df787">begin</a>();
    rtv::Trie&lt;char, std::string&gt;::Iterator iend = dictionary.<a name="a3"></a><a class="code" href="classrtv_1_1_trie.html#a3bfd08ed64b9fffbb6ff18d3bbd5ff00">end</a>();

    std::cout &lt;&lt; <span class="stringliteral">&quot;Iterator with ++&quot;</span> &lt;&lt; std::endl;
    <span class="keywordflow">for</span> (; iter != iend; ++iter) {
        std::cout &lt;&lt; iter-&gt;first  &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; iter-&gt;second-&gt;c_str() &lt;&lt; std::endl;
    }

    <span class="keyword">const</span> <a class="code" href="classrtv_1_1_trie.html" title="Trie main class.">rtv::Trie&lt;char, std::string&gt;</a> &amp; const_ref_dictionary = dictionary;
    rtv::Trie&lt;char, std::string&gt;::ConstIterator const_iter = const_ref_dictionary.<a class="code" href="classrtv_1_1_trie.html#ae72e5f97be19cbb9fe5da0c7f37df787">begin</a>();
    rtv::Trie&lt;char, std::string&gt;::ConstIterator const_iend = const_ref_dictionary.<a class="code" href="classrtv_1_1_trie.html#a3bfd08ed64b9fffbb6ff18d3bbd5ff00">end</a>();

    std::cout &lt;&lt; <span class="stringliteral">&quot;ConstIterator with ++&quot;</span> &lt;&lt; std::endl;
    <span class="keywordflow">for</span> (; const_iter != const_iend; ++const_iter) {
        std::cout &lt;&lt; const_iter-&gt;first  &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; const_iter-&gt;second-&gt;c_str() &lt;&lt; std::endl;
    }

    std::cout &lt;&lt; <span class="stringliteral">&quot;Iterator with --&quot;</span> &lt;&lt; std::endl;
    iter = iend;
    <span class="keywordflow">for</span> (--iter; iter != iend; --iter) {
        std::cout &lt;&lt; iter-&gt;first  &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; iter-&gt;second-&gt;c_str() &lt;&lt; std::endl;
    }

    std::cout &lt;&lt; <span class="stringliteral">&quot;ConstIterator with --&quot;</span> &lt;&lt; std::endl;
    const_iter = const_iend;
    <span class="keywordflow">for</span> (--const_iter; const_iter != const_iend; --const_iter) {
        std::cout &lt;&lt; const_iter-&gt;first  &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; const_iter-&gt;second-&gt;c_str() &lt;&lt; std::endl;
    }

    <span class="keywordflow">return</span> 0;
}
</pre></div> </div><!-- contents -->
</div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Thu Jun 21 2012 20:18:39 for Trie by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
